package cc.mrbird.febs.system.service.impl;

import cc.mrbird.febs.common.domain.FebsConstant;
import cc.mrbird.febs.common.domain.QueryRequest;
import cc.mrbird.febs.common.utils.SortUtil;
import cc.mrbird.febs.system.dao.GroupMapper;
import cc.mrbird.febs.system.dao.GroupUserMapper;
import cc.mrbird.febs.system.domain.CostList;
import cc.mrbird.febs.system.domain.Group;
import cc.mrbird.febs.system.domain.HospitalData;
import cc.mrbird.febs.system.domain.User;
import cc.mrbird.febs.system.service.GroupService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author 福小林
 */
@Slf4j
@Service("groupService")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements GroupService {

    @Resource
    GroupUserMapper groupUserMapper;
    @Override
    public IPage<Group> findGroupDetail(Group group, QueryRequest queryRequest) {
        try {
            Page<User> page = new Page<>();
            SortUtil.handlePageSort(queryRequest, page, "id", FebsConstant.ORDER_ASC, false);
            return this.baseMapper.findGroupDetail(page, group);
        } catch (Exception e) {
            log.error("查询用户异常", e);
            return null;
        }
    }

    @Override
    public List<Map<String,Object>> getAvailableMemberList(String deptId) {
        return  this.baseMapper.getAvailableMemberList(deptId);
    }

    @Override
    public List<String> getGroupUserIds(String groupId) {
        return this.baseMapper.getGroupUserIds(groupId);
    }

    @Override
    public List<Map<String, Object>> getBydeptId(String deptId) {

        return  this.baseMapper.getBydeptId(deptId);
    }

    @Override
    public List<HospitalData> getOutpatientStatisticsPageExcel(Map<String,Object> map) {
        return this.groupUserMapper.getOutpatientStatisticsPageExcel(map);
    }

    @Override
    public List<Map<String, Object>> getGroupListById(String ids) {
        return this.groupUserMapper.getGroupListById(ids) ;
    }

    @Override
    public List<Map<String,Object>> getOutpatientStatistics(Map<String, Object> map) {
        return this.groupUserMapper.getOutpatientStatistics(map);
    }

    @Override
    public IPage<HospitalData> getOutpatientStatisticsPage(Page page,Map<String, Object> searchData) {
        return this.groupUserMapper.getOutpatientStatisticsPage( page,searchData) ;
    }

    @Override
    public List<CostList> getOutpatientStatisticsListPage(Map<String, Object> map) {
        return this.groupUserMapper.getOutpatientStatisticsListPage(map);
    }
    @Override
    public List<CostList> getDrugProportion(Map<String, Object> map) {
        return this.groupUserMapper.getDrugProportion(map);
    }

    @Override
    public List<Map<String, Object>> getOutpatientStatisticsList(Map<String, Object> map) {
        return this.groupUserMapper.getOutpatientStatisticsList(map);
    }
}
